<template>
  <div class="dailyTask" v-title data-title="缺陷任务单明细">
    <home-nav :userData="userinfo"></home-nav>
    <div class="navigator">
      <div class="baseinfo">
        <div style="display: flex">
          <span style="margin: 0px auto 10px auto; font-weight: bold; font-size: 20px">缺陷任务单明细</span>
          <span style="color: #31a0e1" v-show="id" @click="openHistory">操作日志</span>
        </div>
        <div class="info-title">关联的任务单信息</div>
        <a-form-model class="hte-form-model" ref="ruleForm" :model="form">
          <div v-show="form.taskBuildType != '3'">
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item label="任务单编号">
                  <a-input v-model="form.taskNo" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="任务单分类">
                  <a-input v-model="form.taskTypeName" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="任务单名称">
                  <a-input v-model="form.taskName" disabled />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item label="创建人">
                  <a-input v-model="form.createUserName" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item class="disable-input-bg" label="创建时间">
                  {{ dateFormat(form.createDate) }}
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="主导团队">
                  <a-input v-model="form.mainDeptName" disabled />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item ref="taskBuildType" label="任务单类型" prop="taskBuildType">
                  <a-radio-group v-model="form.taskBuildType" disabled>
                    <a-radio value="1">个人</a-radio>
                    <a-radio value="2">团队</a-radio>
                  </a-radio-group>
                </a-form-model-item>
              </a-col>

              <a-col :span="8" v-if="form.taskType == '30'">
                <a-form-model-item label="产品系统">
                  <a-input v-model="form.productSystemName" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8" v-if="form.taskType == '30'">
                <a-form-model-item label="迭代负责人">
                  <a-input v-model="form.handlerName" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item class="disable-input-bg" label="任务开始时间">
                  {{ dateFormat(form.startDate) }}
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="任务计划完成时间" class="disable-input-bg">
                  {{ dateFormat(form.endDate) }}
                </a-form-model-item>
              </a-col>
              <a-col :span="8" v-if="form.taskType == '30'">
                <a-form-model-item label="版本号">
                  <a-input v-model="form.versionNo" disabled />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24" v-if="form.taskType == '30'">
              <a-col :span="24">
                <a-form-model-item ref="hasSendNotice" label="是否已上线" prop="hasSendNotice">
                  <a-tooltip>
                    <template slot="title">
                      <span
                        >是否已上线是指【整个任务单的完成状态是以该字段为准，即使所有子任务已完成】<br />当所有子任务和缺陷都完成时，任务单创建人或迭代负责人可修改该状态。</span
                      >
                    </template>
                    <a-radio-group v-model="form.hasSendNotice" disabled>
                      <a-radio value="1">未完成</a-radio>
                      <a-radio value="2">已完成并且已发通知</a-radio>
                      <a-radio value="3">已完成但无需发通知</a-radio>
                    </a-radio-group>
                  </a-tooltip>
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="24">
                <a-form-model-item label="开放范围:">
                  <a-textarea
                    v-model="form.openRangeName"
                    :auto-size="{ minRows: 1, maxRows: 5 }"
                    style="width: 100%"
                    disabled
                    readOnly
                  />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="24">
                <a-form-model-item label="任务单完成目标:">
                  <a-textarea
                    v-model="form.target"
                    :auto-size="{ minRows: 3, maxRows: 5 }"
                    style="width: 100%"
                    disabled
                    readOnly
                  />
                </a-form-model-item>
              </a-col>
            </a-row>
          </div>
          <div v-show="form.taskBuildType == '3'">
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item label="任务单编号">
                  <a-input v-model="form.taskNo" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="任务单名称">
                  <a-input v-model="form.taskName" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item label="项目信息">
                  <a-input v-model="projectNoAndName" disabled />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="8">
                <a-form-model-item label="项目节点" prop="timeNodeCode">
                  <a-select
                    v-model="form.timeNodeCode"
                    placeholder="请选择未报工的项目节点"
                    :options="timeNodeCodeOptions"
                    notFoundContent="请先选择项目"
                    disabled
                    style="width: 100%"
                  >
                    <a-icon slot="suffixIcon" type="plus" />
                  </a-select>
                </a-form-model-item>
              </a-col>
              <div v-if="form.projectNo != ''">
                <a-col :span="8" v-if="form.taskType == '30'">
                  <a-form-model-item label="产品系统">
                    <a-input v-model="form.productSystemName" disabled />
                  </a-form-model-item>
                </a-col>

                <a-col :span="8" v-if="form.projectNo != '' && form.taskType == '30'">
                  <a-form-model-item label="迭代负责人">
                    <a-input v-model="form.handlerName" disabled />
                  </a-form-model-item>
                </a-col>

                <a-col :span="8">
                  <a-form-model-item label="创建人">
                    <a-input v-model="form.createUserName" disabled />
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="创建时间" class="disable-input-bg">
                    {{ form.createDate ? timeFormat(form.createDate) : nowDate }}
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item label="主导经营体">
                    <a-input v-model="form.mainDeptName" disabled />
                  </a-form-model-item>
                </a-col>
              </div>
              <div v-if="form.timeNodeCode">
                <a-col :span="8">
                  <a-form-model-item class="disable-input-bg" label="节点开始时间">
                    {{ timeFormat(form.startDate) }}
                  </a-form-model-item>
                </a-col>
                <a-col :span="8">
                  <a-form-model-item class="disable-input-bg" label="节点完成时间">
                    {{ timeFormat(form.endDate) }}
                  </a-form-model-item>
                </a-col>
                <a-col :span="8" v-if="form.projectNo != '' && form.taskType == '30'">
                  <a-form-model-item label="版本号">
                    <a-input v-model="form.versionNo" disabled />
                  </a-form-model-item>
                </a-col>
              </div>
            </a-row>
            <a-row :gutter="24" v-if="form.taskType == '30'">
              <a-col :span="8">
                <a-form-model-item ref="businessConfirm" label="需要审批确认" prop="businessConfirm">
                  <a-input :value="form.businessConfirm == '1' ? '是' : '否'" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item ref="hasSendNotice" label="是否已上线" prop="hasSendNotice">
                  <a-input
                    :value="
                      form.hasSendNotice == '1'
                        ? '未完成'
                        : form.hasSendNotice == '2'
                        ? '已完成并且已发通知'
                        : '已完成但无需发通知'
                    "
                    disabled
                  />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item ref="testUserName" label="测试员" prop="testUserName">
                  <a-input :value="form.testUserName" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item ref="qualityScore" label="质量分" prop="qualityScore">
                  <a-input v-model="form.qualityScore" disabled />
                </a-form-model-item>
              </a-col>
              <a-col :span="8">
                <a-form-model-item ref="testConfirmDate" class="disable-input-bg" label="测试时间" prop="testConfirmDate">
                  {{ timeFormat(form.testConfirmDate) }}
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24" v-if="form.taskType == '30'">
              <a-col :span="24">
                <a-form-model-item label="测试结果">
                  <a-textarea
                    v-model="form.testConfirm"
                    :auto-size="{ minRows: 1, maxRows: 5 }"
                    style="width: 100%"
                    disabled
                    readOnly
                  />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row :gutter="24">
              <a-col :span="24">
                <a-form-model-item label="开放范围:">
                  <a-textarea
                    v-model="form.openRangeName"
                    :auto-size="{ minRows: 1, maxRows: 5 }"
                    style="width: 100%"
                    disabled
                    readOnly
                  />
                </a-form-model-item>
              </a-col>
            </a-row>
            <div v-if="form.timeNodeCode">
              <a-row :gutter="24">
                <a-col :span="24">
                  <a-form-model-item label="任务单完成目标:">
                    <a-textarea
                      v-model="form.target"
                      :auto-size="{ minRows: 3, maxRows: 5 }"
                      style="width: 100%"
                      disabled
                      readOnly
                    />
                  </a-form-model-item>
                </a-col>
              </a-row>
            </div>
          </div>
        </a-form-model>
        <a-divider style="margin: 10px 0" />
        <div class="info-title" style="margin-top: 10px">
          相关附件
          <ht-upload
            ref="myUpload"
            class="upload-demo"
            multiple
            dbKey="Trd"
            busField="workTask"
            busType="workTask"
            :busKey="busKeyId"
            ftpKey="ftp"
            v-model="fileList"
            :show-file-list="false"
          >
            <a-button type="primary"><a-icon type="plus" />新增附件</a-button>
          </ht-upload>
            <span>
              <img src="@/assets/attention-red.png" alt="" style="width:12px;margin: 0px 5px 0px 5px;"/>
              <span style="font-size: 14px;">附件非必填，如有相关附件可以上传，例如收益计算明细，计算方法，该任务单的方案、规划、工作要求等。</span>
            </span>
        </div>
        <div style="margin-top: 10px">
          <a-table
            class="hte-table-content"
            :columns="uploadColumns"
            :data-source="fileQueryList"
            :pagination="false"
            :rowKey="
              (record, index) => {
                return index
              }
            "
            bordered
            size="middle"
            v-show="fileQueryList.length > 0"
          >
            <a
              slot="name"
              slot-scope="text, record"
              @click="previewAttach(record.id, record.fileName)"
              href="javascript:void(0)"
              title="点击预览附件"
              style="color: blue"
              >{{ text }}</a
            >
            <span slot="uploadTime" slot-scope="text">
              {{ dateFormat(text) }}
            </span>
            <span slot="aciton" slot-scope="text, record">
              <span
                style="color: blue; cursor: pointer"
                @click="deletefj(record.id)"
                type="primary"
                v-if="record.uploader == currentUserId"
                >删除</span
              >
              <span
                style="color: blue; cursor: pointer; margin-left: 5px"
                @click="doDownLoadBatch(record.id)"
                type="primary"
                >下载</span
              >
            </span>
          </a-table>
        </div>

        <a-divider style="margin: 10px 0" />

        <div>
          <div class="info-title">
            缺陷明细
            <a-button type="primary" @click="kpiAdd()" :disabled="!kpi.selRowIds.length > 0">一键报工</a-button>
          </div>
          <a-table
            class="hte-table-content"
            :row-selection="rowSelection"
            :columns="kpi.columns"
            :data-source="kpi.data"
            bordered
            size="middle"
            :rowKey="(record) => record.id"
            :pagination="false"
          >
            <template slot="bugLevel" slot-scope="text">
              {{ text == '1' ? '致命' : text == '2' ? '严重' : text == '3' ? '一般' : '建议/提醒' }}
            </template>
            <template slot="startDate" slot-scope="text, record">
              {{ dateFormat(record.startDate) }}
            </template>
            <template slot="endDate" slot-scope="text, record">
              {{ dateFormat(record.endDate) }}
            </template>
            <template slot="realCompletionDate" slot-scope="text, record">
              <span v-if="record.detailStatus == '2' || currentUserId != record.handleUserId">{{
                dateFormat(record.realCompletionDate)
              }}</span>
              <a-date-picker
                v-else
                v-model="record.realCompletionDate"
                placeholder="请输入实际完成时间"
                allowClear
                @change="
                  (date, dateString) => {
                    realTimeSelect(date, dateString, record)
                  }
                "
                :disabled-date="disabledCurrent"
              />
            </template>
            <template slot="reportMemo" slot-scope="text, record">
              <span v-if="record.detailStatus == '2' || currentUserId != record.handleUserId">{{ text }}</span>
              <a-textarea
                v-else
                v-model="record.reportMemo"
                :auto-size="{ minRows: 1 }"
                style="width: 100%"
                placeholder="请填写完成情况，500字内"
                :maxLength="500"
              />
            </template>
            <template slot="delayMemo" slot-scope="text, record">
              <span
                v-if="
                  record.detailStatus == '2' ||
                  currentUserId != record.handleUserId ||
                  delayIds.indexOf(record.id) == -1
                "
                >{{ text }}</span
              >
              <a-textarea
                v-else
                v-model="record.delayMemo"
                :auto-size="{ minRows: 1 }"
                style="width: 100%"
                placeholder="请填写延误原因，500字内"
                :maxLength="500"
              />
            </template>
            <template slot="bugStatus" slot-scope="text, record">
              {{ record.detailStatus != '2' ? '待处理' : initBugStatus(text) }}
            </template>
            <template slot="action" slot-scope="text, record">
              <a v-if="record.detailStatus == '3' && currentUserId == record.handleUserId" @click="detailReport(record)"
                >报工</a
              >
              <a
                v-if="
                  record.detailStatus == '2' &&
                  currentUserId == record.createUserId &&
                  (!record.bugStatus || record.bugStatus == '1')
                "
                @click="closeDetail(record)"
                >关闭</a
              >
              <a
                v-if="
                  record.detailStatus == '2' &&
                  currentUserId == record.createUserId &&
                  (!record.bugStatus || record.bugStatus == '2')
                "
                @click="reOpenDetail(record)"
                style="margin-left: 5px"
                >重新打开</a
              >
            </template>
          </a-table>
        </div>
      </div>
    </div>
    <a-modal
      v-model="visibleModelHistory"
      width="70vw"
      :bodyStyle="{ padding: '10px', backgroundColor: '#f4f5fa' }"
      title="变更历史"
      :footer="null"
      :key="id"
    >
      <task-change-history :hid="id"></task-change-history>
    </a-modal>
  </div>
</template>

<script>
import { getAction, postAction,previewAttach } from '@/api/manage'
import moment from 'moment'
import '@/config/upload.install.js'
import Vue from 'vue'
import { ACCESS_TOKEN, USER_INFO } from '@/store/mutation-types'
import { getParamValFromUrl, formatFileSize, endWith } from '@/utils/common.js'

const uploadColumns = [
  {
    title: '附件名称',
    dataIndex: 'fileName',
    scopedSlots: { customRender: 'name' },
  },
  {
    title: '上传人',
    dataIndex: 'uploaderName',
    width: '10%',
  },
  {
    title: '上传时间',
    dataIndex: 'uploadTime',
    align: 'center',
    width: '15%',
    scopedSlots: { customRender: 'uploadTime' },
  },
  {
    title: '操作',
    dataIndex: 'aciton',
    align: 'center',
    scopedSlots: { customRender: 'aciton' },
    width: '10%',
  },
]

export default {
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    TaskChangeHistory: () => import('@views/myTask/TaskChangeHistory'),
  },
  data() {
    return {
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'dailyTaskDetail',
      },
      uploadColumns,
      selectedRowKeys: [],
      labelCol: { span: 8 },
      wrapperCol: { span: 15 },
      tableSelectKey: '',
      btnShow: false,
      form: {
        id: '',
        taskType: '30',
        taskTypeName: '',
        taskBuildType: '2',
        taskBugType: '1',
        taskName: '',
        startDate: '',
        endDate: '',
        createUserId: '',
        createUserName: '',
        mainDeptId: '',
        mainDeptName: '',
        target: '',
        saveFlag: true,
        status: '',
        taskNo: '',
        versionNo: '',
        handlerId: '',
        handlerName: undefined,
        hasSendNotice: '1',
        openRange: '',
        openRangeName: '',
        productSystem: '',
        productSystemName: '',
        taskBugLevel: undefined,
        projectBuildId: '',
        projectNo: '',
        projectName: '',
        timeNodeCode: '',
        projectTypeSubCategory: '',
        reportMemo: '',
        delayMemo: '',
        planCompletionDate: null,
        realCompletionDate: null,
      },
      url: {
        getAttachInfo: '/tp/attach/getAttaches',
        getWorkTask: '/projectWorkTask/queryByBugId',
        reportTask: '/projectWorkTask/reportTask',
        batchReportTask: '/projectWorkTask/batchReportTask',
        downLoadBatch: '/common/downLoadBatch',
        deleteBatch: '/tp/attach/delete',
        closeDetail: '/projectWorkTask/closeDetail',
        reOpenDetail: '/projectWorkTask/reOpenDetail',
        initTimeNodeOption: '/projectBuildTime/queryListByBuildId',
        getProjectBuildById: '/projectBuild/queryById',
      },
      kpi: {
        columns: [
          {
            title: '序号',
            dataIndex: 'index',
            key: 'index',
            align: 'center',
            width: 50,
            customRender: (text, record, index) => `${index + 1}`,
          },
          {
            title: '缺陷内容',
            align: 'center',
            dataIndex: 'taskContent',
          },
          {
            title: '缺陷等级',
            dataIndex: 'bugLevel',
            align: 'center',
            width: '8%',
            scopedSlots: { customRender: 'bugLevel' },
          },
          {
            title: '修复开始时间',
            dataIndex: 'startDate',
            align: 'center',
            width: '8%',
            scopedSlots: { customRender: 'startDate' },
            sorter: (a, b) => {
              return a.startDate.localeCompare(b.startDate)
            },
          },
          {
            title: '修复完成时间',
            dataIndex: 'endDate',
            align: 'center',
            width: '8%',
            scopedSlots: { customRender: 'endDate' },
            sorter: (a, b) => {
              return a.endDate.localeCompare(b.endDate)
            },
          },
          {
            title: '具体执行人员',
            dataIndex: 'handleUserName',
            align: 'center',
            width: '8%',
          },
          {
            title: '实际完成时间',
            dataIndex: 'realCompletionDate',
            align: 'center',
            width: '8%',
            scopedSlots: { customRender: 'realCompletionDate' },
            sorter: (a, b) => {
              return a.realCompletionDate.localeCompare(b.realCompletionDate)
            },
          },
          {
            title: '具体完成情况',
            dataIndex: 'reportMemo',
            align: 'center',
            width: '10%',
            scopedSlots: { customRender: 'reportMemo' },
          },
          {
            title: '延误原因',
            dataIndex: 'delayMemo',
            align: 'center',
            width: '10%',
            scopedSlots: { customRender: 'delayMemo' },
          },
          {
            title: 'bug状态',
            dataIndex: 'bugStatus',
            align: 'center',
            width: '8%',
            scopedSlots: { customRender: 'bugStatus' },
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            width: '10%',
            scopedSlots: { customRender: 'action' },
          },
        ],
        data: [],
        selRowIds: [],
      },
      fileList: [],
      fileQueryList: [],
      id: '',
      addFlag: false,
      currentUserId: '',
      delayFlag: false,
      detailStartDate: '',
      detailEndDate: '',
      reportFlag: false,
      currentIndex: '',
      delayIds: [],
      busKeyId: this.id + '_bugId',
      projectNoAndName: '',
      timeNodeCodeOptions: [],
      visibleModelHistory: false,
    }
  },
  created() {
    const obj = this.$route.query
    this.id = obj.id
    this.initData(this.id)
    this.currentUserId = Vue.ls.get(USER_INFO).username
  },
  methods: {
    initTimeNodeOption(id) {
      var vm = this
      vm.timeNodeCodeOptions = []
      //vm.form.timeNodeCode = ''
      getAction(vm.url.initTimeNodeOption, { projectBuildId: id }).then((res) => {
        if (res.code === 200) {
          vm.timeListData = res.result || []
          let newarr = vm.timeListData.filter((item) => {
            return item.reportStatus == null || item.reportStatus != '2'
          })
          newarr.forEach((element) => {
            vm.timeNodeCodeOptions.push({
              label: element.timeNode,
              value: element.timeNodeCode,
            })
          })
        } else {
          //const msg = res.message == null ? res.data : res.message;
          this.$message.error(res.message)
        }
      })
    },
    timeFormat(time) {
      if (time) {
        return moment(time).format('YYYY-MM-DD')
      } else {
        return ''
      }
    },
    disabledCurrent(current) {
      return current > moment().endOf('day')
    },
    realTimeSelect(date, dateString, record) {
      if (dateString && moment(dateString).diff(moment(record.endDate), 'day') > 0) {
        this.delayFlag = true
      } else {
        this.delayFlag = false
        record.delayMemo = ''
      }
    },
    initData(id) {
      const _this = this
      getAction(_this.url.getWorkTask, { id: id }).then((res) => {
        if (res.code === 200) {
          _this.form = res.result
          _this.kpi.data = res.result.detail
          if (this.form.taskBuildType == '3') {
            this.initTimeNodeOption(res.result.projectBuildId)
            getAction(this.url.getProjectBuildById, { id: this.form.projectBuildId }).then((resProject) => {
              this.form.projectNo = resProject.result.projectNo
              this.form.projectName = resProject.result.projectName
              this.projectNoAndName = resProject.result.projectNo + ' && ' + resProject.result.projectName
            })
          }
          _this.loadAttachInfo()

          _this.kpi.data.forEach((item) => {
            if (
              item.handleUserId === _this.currentUserId &&
              item.detailStatus != '2' &&
              (item.planCompletionDate
                ? moment(item.planCompletionDate).diff(item.endDate, 'day') > 0 ||
                  (item.realCompletionDate
                    ? moment(item.realCompletionDate).diff(item.endDate, 'day') > 0
                    : moment(moment().format('YYYY-MM-DD')).diff(item.endDate, 'day') > 0)
                : item.realCompletionDate
                ? moment(item.realCompletionDate).diff(item.endDate, 'day') > 0
                : moment(moment().format('YYYY-MM-DD')).diff(item.endDate, 'day') > 0)
            ) {
              _this.delayIds.push(item.id)
            }
          })
        } else {
          this.$message.error(res.message)
        }
      })
    },
    loadAttachInfo() {
      const that = this
      getAction(this.url.getAttachInfo, {
        dbKey: 'Trd',
        busKey: this.busKeyId,
        busField: 'workTask',
        busType: 'workTask',
        ftpKey: 'ftp',
      }).then((res) => {
        // if (that.currentUserId != that.form.createUserId) {
        //   var newarr = res.data.filter(item => {
        //     return item.uploader == that.currentUserId  ||  item.uploader == that.form.createUserId
        //   })
        //   this.fileQueryList = newarr || []
        // } else {
        //   this.fileQueryList = res.data || []
        // }
        this.fileQueryList = res.data || []
      })
    },
    previewAttach(attachId, fileName) {
      if (
        endWith(fileName, 'rar') ||
        endWith(fileName, 'zip') ||
        endWith(fileName, 'dwg') ||
        endWith(fileName, 'tgz')
      ) {
        this.doDownLoadBatch(attachId)
        return
      }

      let params={
        id:attachId,
        ftpKey:'ftp'
      };
      previewAttach(params).then(result=>{
        const url=URL.createObjectURL(result)
        window.open(process.env.BASE_URL+'/pdf/web/viewer.html?file=' + url)
      }).catch(err => {
        this.$message.warning('下载文件失败');
      })
    },
    doDownLoadBatch(attachIds) {
      if (document.getElementById('_attachToolView_downloadfile_frame') == null) {
        let downloadFrame = $('<iframe id="_attachToolView_downloadfile_frame" style="display: none"></iframe>')
        downloadFrame.appendTo($('body'))
      }
      let iframe = document.getElementById('_attachToolView_downloadfile_frame')
      iframe.src =
        this.API_BASE_URL +
        this.url.downLoadBatch +
        '?attachIds=' +
        attachIds +
        '&dbKey=Trd&ftpKey=ftp&token=' +
        Vue.ls.get(ACCESS_TOKEN)
    },
    // 绑busKey
    bindBusKey() {
      if (this.fileList.length > 0) {
        const ids = this.fileList.map(function (item) {
          return item.id
        })
        const jsona = { dbKey: 'Trd', id: ids.toString(), busKey: this.busKeyId }
        var jsonStr = JSON.stringify(jsona)
        this.$refs.myUpload.bindBusKey(jsonStr)
      }
    },
    deletefj(id) {
      const that = this
      this.$confirm({
        title: '是否确认删除？',
        onOk() {
          postAction(that.url.deleteBatch, { id: id, busField: 'workTask', busType: 'workTask', ftpKey: 'ftp' })
            .then((res) => {
              if (res.code == 1) {
                that.$message.success('删除成功')
                that.fileQueryList.splice(
                  that.fileQueryList.findIndex((item) => item.id === id),
                  1
                )
                that.fileList.splice(
                  that.fileList.findIndex((item) => item.id === id),
                  1
                )
              } else {
                that.$message.warning('删除失败:' + res.msg)
              }
            })
            .catch((res) => {
              that.$message.warning('删除失败:' + res.msg)
            })
        },
        onCancel() {},
      })
    },
    dateFormat(date) {
      return date ? moment(date).format('YYYY-MM-DD') : ''
    },
    kpiAdd() {
      if (this.kpi.selRowIds.length == 0) {
        this.$message.warning('请选择要报工的明细记录')
        return
      }
      for (var i = 0; i < this.kpi.selRowIds.length; i++) {
        if (this.delayIds.indexOf(this.kpi.selRowIds[i].id) > -1 && !this.kpi.selRowIds[i].delayMemo) {
          this.$message.warning(`缺陷内容为${this.kpi.selRowIds[i].taskContent}的记录已延误，请填写延误原因`)
          return
        }
        if (!this.kpi.selRowIds[i].realCompletionDate) {
          this.$message.warning(`缺陷内容为${this.kpi.selRowIds[i].taskContent}的记录实际完成时间未填写，请填写`)
          return
        }
      }

      let arr = []
      for (var i = 0; i < this.kpi.selRowIds.length; i++) {
        var obj = {}
        obj.id = this.form.id
        obj.detailId = this.kpi.selRowIds[i].id
        obj.reportMemo = this.kpi.selRowIds[i].reportMemo ? this.kpi.selRowIds[i].reportMemo : '已完成'
        obj.delayMemo = this.kpi.selRowIds[i].delayMemo
        obj.comfirmFlag = true
        obj.realCompletionDate = this.kpi.selRowIds[i].realCompletionDate
        obj.bugType = '1'
        arr.push(obj)
      }
      const that = this
      this.$confirm({
        title: '是否确认一键报工',
        onOk() {
          postAction(that.url.batchReportTask, arr)
            .then((res) => {
              if (res.code === 200) {
                that.$message.success('一键报工成功')
                that.initData(that.form.id)
              } else {
                const msg = res.message == null ? res.result : res.message
                that.$message.error(msg)
              }
              that.kpi.selRowIds = []
              that.selectedRowKeys = []
            })
            .catch((err) => {
              console.log(err)
            })
        },
        onCancel() {},
      })
    },
    detailReport(record) {
      if (!record.realCompletionDate) {
        this.$message.warning('实际完成时间不能为空')
        return
      }
      if (this.delayFlag && !record.delayMemo) {
        this.$message.warning('延误原因不能为空')
        return
      }
      if (!record.reportMemo) {
        record.reportMemo = '已完成'
      }
      var obj = {}
      obj.id = this.form.id
      obj.detailId = record.id
      obj.reportMemo = record.reportMemo
      obj.delayMemo = record.delayMemo
      obj.comfirmFlag = true
      obj.realCompletionDate = record.realCompletionDate
      obj.bugType = '1'
      const that = this
      this.$confirm({
        title: '是否确认报工',
        onOk() {
          postAction(that.url.reportTask, obj)
            .then((res) => {
              if (res.code === 200) {
                that.$message.success('报工成功')
                that.initData(that.form.id)
              } else {
                const msg = res.message == null ? res.result : res.message
                that.$message.error(msg)
              }
            })
            .catch((err) => {
              console.log(err)
            })
        },
        onCancel() {},
      })
    },
    initBugStatus(text) {
      switch (text) {
        case 1:
          return '复测不通过'
          break
        case 2:
          return '复测通过'
          break
        case 3:
          return '待复测'
          break
        default:
          return '待复测'
      }
    },
    closeDetail(record) {
      const that = this
      this.$confirm({
        title: '是否确认关闭该缺陷',
        onOk() {
          postAction(that.url.closeDetail, record)
            .then((res) => {
              if (res.code === 200) {
                that.$message.success('关闭缺陷成功')
                that.initData(that.form.id)
              } else {
                const msg = res.message == null ? res.result : res.message
                that.$message.error(msg)
              }
            })
            .catch((err) => {
              console.log(err)
            })
        },
        onCancel() {},
      })
    },
    reOpenDetail(record) {
      const that = this
      this.$confirm({
        title: '是否确认重新打开缺陷',
        onOk() {
          postAction(that.url.reOpenDetail, record)
            .then((res) => {
              if (res.code === 200) {
                that.$message.success('重新打开缺陷成功')
                that.initData(that.form.id)
              } else {
                const msg = res.message == null ? res.result : res.message
                that.$message.error(msg)
              }
            })
            .catch((err) => {
              console.log(err)
            })
        },
        onCancel() {},
      })
    },
    openHistory() {
      this.visibleModelHistory = true
    },
  },
  watch: {
    fileList: function (newQuestion, oldQuestion) {
      // this.bindBusKey()
      newQuestion.forEach((item) => {
        var newIndex = this.fileQueryList.findIndex((item2) => item2.id === item.id)
        if (newIndex == -1) {
          this.fileQueryList.push(item)
        }
      })
    },
  },
  computed: {
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.kpi.selRowIds = selectedRows
          this.selectedRowKeys = selectedRowKeys
        },
        getCheckboxProps: (record) => ({
          props: {
            disabled: !(record.detailStatus == '3' && this.currentUserId == record.handleUserId),
          },
        }),
      }
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
.dailyTask {
  height: 100%;
  font-size: 14px;
  .navigator {
    min-height: 100%;
    padding: 27px 125px 50px;
    background-color: #f5f5f5;
  }
}
.baseinfo {
  background-color: #fff;
  border: 1px solid #eaeaea;
  padding: 20px;
  .btn-box {
    display: flex;
    justify-content: center;
    margin-top: 20px;
  }
}
.info-title {
  font-size: 16px;
  font-weight: bold;
  position: relative;
  padding-left: 14px;
  color: #333333;
  margin-bottom: 14px;
  &:before {
    content: '';
    position: absolute;
    display: block;
    height: 70%;
    top: 15%;
    width: 3px;
    left: 0;
    background-color: #47a4fa;
  }
  /deep/ .ant-btn {
    margin-left: 10px;
    height: 30px;
    line-height: 30px;
  }
}
/deep/ .el-upload__input {
  display: none !important;
}
/deep/ .ant-calendar-picker {
  width: 100%;
}
/deep/ .rowClass {
  background-color: #e6f7ff;
  &:hover:not(.ant-table-expanded-row):not(.ant-table-row-selected) > td {
    background-color: #cae9fb;
  }
}
/deep/ .upload-demo {
  display: inline-block;
}
/deep/ .report label {
  color: red;
}
@media (max-width: 1080px) {
  .dailyTask .navigator {
    padding: 27px 30px 50px !important;
  }
}
</style>